#include "GuiChoice.hpp"
#include "GuiDialog.hpp"
#include "../Core.hpp"
#include "../RenderingSystem/FontRenderer.hpp"

GuiChoice::GuiChoice(DialogManager * dialogManager, Core* core)
{
    m_core= core;
    m_dialogManager = dialogManager;
    status = D_INACTIVE;
    choice = true;

    if(!textBubbleTexture.loadFromFile("Ressources/sprites/textChoice.png"))
	{
		printf("ERROR -- Can't load the text bubble");
		exit(-1);
	}

	textBubbleSprite.setTexture(textBubbleTexture);
	textBubbleSprite.setPosition(WINDOW_WIDTH/2 - 790/2, WINDOW_HEIGHT-220);

	if(!cursorTexture.loadFromFile("Ressources/sprites/cursor.png"))
	{
		printf("ERROR -- Can't load the text bubble");
		exit(-1);
	}

	cursorSprite.setTexture(cursorTexture);
	cursorSprite.setPosition(WINDOW_WIDTH/2 - 790/2 + 10, WINDOW_HEIGHT-220);
}

GuiChoice::~GuiChoice()
{

}

void GuiChoice::update()
{
    if(choice)
        cursorSprite.setPosition(WINDOW_WIDTH/2 - 790/2 + 25, WINDOW_HEIGHT-195);
    else
        cursorSprite.setPosition(WINDOW_WIDTH/2 - 790/2 + 25, WINDOW_HEIGHT-150);
}

void GuiChoice::draw(sf::RenderWindow*window)
{
   if(isActiveOrWaiting())
	{
		window->draw(textBubbleSprite);
		m_core->fontRenderer->printString("Oui", WINDOW_WIDTH/2 - 790/2 + 50, WINDOW_HEIGHT-182, sf::Color(0,0,0),18);
        m_core->fontRenderer->printString("Non", WINDOW_WIDTH/2 - 790/2 + 50, WINDOW_HEIGHT-137, sf::Color(0,0,0),18);
		window->draw(cursorSprite);
	}
}

void GuiChoice::newChoice(std::string yes, std::string no)
{
    choice = true;
    m_yes = yes;
    m_no= no;
    status = D_ACTIVE;
}

void GuiChoice::upDownInput()
{
    if(choice)
        choice = false;
    else
        choice = true;
}

void GuiChoice::returnInput()
{
    if(choice)
        m_dialogManager->getDialogBox()->addDialogChunk(m_yes);
    else
        m_dialogManager->getDialogBox()->addDialogChunk(m_no);

    status = D_INACTIVE;

}

bool GuiChoice::getChoice()
{
    return choice;
}
